<template>
  <div class="middle-menu">
    <div class="menu-header">
      <span>菜单列表</span>
    </div>
    <el-menu
      :default-active="activeMenu"
      class="menu-list"
      @select="handleSelect"
    >
      <el-menu-item v-for="item in menuItems" :key="item.id" :index="item.id">
        <el-icon><component :is="item.icon" /></el-icon>
        <span>{{ item.name }}</span>
      </el-menu-item>
    </el-menu>
  </div>
</template>

<script setup>
import { ref } from 'vue'
import { Document, DataLine, PieChart, Histogram } from '@element-plus/icons-vue'

const activeMenu = ref('1')

// 模拟从后端获取的菜单数据
const menuItems = ref([
  { id: '1', name: '工资报表', icon: 'Document' },
  { id: '2', name: '考勤统计', icon: 'DataLine' },
  { id: '3', name: '绩效分析', icon: 'PieChart' },
  { id: '4', name: '加班统计', icon: 'Histogram' }
])

const handleSelect = (index) => {
  activeMenu.value = index
  // 触发事件通知父组件更新右侧报表
  emit('menuSelect', index)
}

const emit = defineEmits(['menuSelect'])
</script>

<style scoped>
.middle-menu {
  height: 100%;
  display: flex;
  flex-direction: column;
}

.menu-header {
  height: 50px;
  line-height: 50px;
  padding: 0 20px;
  font-size: 16px;
  font-weight: 600;
  border-bottom: 1px solid #e6e6e6;
}

.menu-list {
  flex: 1;
  border-right: none;
}

.menu-list :deep(.el-menu-item) {
  height: 50px;
  line-height: 50px;
}

.menu-list :deep(.el-menu-item.is-active) {
  background-color: #ecf5ff;
  color: #409EFF;
}
</style> 